<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置一个memcached选项</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="memcached.setmultibykey.html">« Memcached::setMultiByKey</a></li>
      <li style="float: right;"><a href="memcached.setoptions.html">Memcached::setOptions »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.memcached.html">Memcached</a></li>
    <li>设置一个memcached选项</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="memcached.setoption" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Memcached::setOption</h1>
  <p class="verinfo">(PECL memcached &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">Memcached::setOption</span> &mdash; <span class="dc-title">设置一个memcached选项</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-memcached.setoption-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Memcached::setOption</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$option</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
  这个方法用来设置Memcached <code class="parameter">option</code>的值。一些选项和libmemcached中定义的类似， 还有一些则是
  扩展所特有的。关于选项的更多信息请参阅<a href="memcached.constants.html" class="link">Memcached Constants</a>。
  </p>
  <p class="para">
  下面的选项列表需要通过特定的常量指定值。
   <ul class="itemizedlist">
    <li class="listitem"><p class="para">
      <code class="literal">Memcached::OPT_HASH</code>需要<code class="literal">Memcached::HASH_*</code>系列常量值。
    </p></li>
    <li class="listitem"><p class="para">
      <code class="literal">Memcached::OPT_DISTRIBUTION</code>需要<code class="literal">Memcached::DISTRIBUTION_*</code>系列常量值。
    </p></li>
   </ul>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-memcached.setoption-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-memcached.setoption-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4409">
    <p><strong>示例 #1 设置一个memcached选项值</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_HASH</span><span style="color: #007700">)&nbsp;==&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">HASH_DEFAULT</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_HASH</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">HASH_MURMUR</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_PREFIX_KEY</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"widgets"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"Prefix&nbsp;key&nbsp;is&nbsp;now:&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOption</span><span style="color: #007700">(</span><span style="color: #0000BB">Memcached</span><span style="color: #007700">::</span><span style="color: #0000BB">OPT_PREFIX_KEY</span><span style="color: #007700">),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
bool(true)
Prefix key is now: widgets
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-memcached.setoption-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="memcached.getoption.html" class="methodname" rel="rdfs-seeAlso">Memcached::getOption()</a> - 获取Memcached的选项值</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>